const consts = {
    sessionKeys: {
        JWT_TOKEN: "JWT_TOKEN",
        LOGIN_USER_DESC: "LOGIN_USER_DESC",
        CURRENT_DEPT: "CURRENT_DEPT"
    },
    exceptions: {
        NUM_LENGTH_TOO_LONG: {
            key: "NumLengthTooLong",
            msg: "数字太大，超出限制!"
        }

    }
};
const funs = {
    getObjFromSessionStorage: function (key) {
        let jsonStr = localStorage.getItem(key)
        if (utils.isEmpty(jsonStr)) {
            return null;
        }
        return JSON.parse(jsonStr);
    },
    loginUserInfo: function () {
        return this.getObjFromSessionStorage(consts.sessionKeys.LOGIN_USER_DESC);
    },
    getCurrentStore: function () {
        return this.getObjFromSessionStorage(consts.sessionKeys.CURRENT_DEPT);
    }
};
const utils = {
    isEmpty: function (str) {
        if (str == null) {
            return true;
        } else {
            if (str == '') {
                return true;
            } else {
                return false;
            }
        }
    },
    numberFormat: function (num, tarLen) {
        num = "" + num;
        if (tarLen == num.length) {
            return num;
        } else if (num.length > tarLen) {
            throw consts.exceptions.NUM_LENGTH_TOO_LONG.key;
        } else {
            var fillLen = tarLen - num.length;
            for (let i = 0; i < fillLen; i++) {
                num = "0" + num;
            }
            return num;
        }
    }
};

export default {consts, funs, utils}